﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static UnityEngine.GraphicsBuffer;
using UnityEditor;
using UnityEngine;


#if UNITY_EDITOR

[CustomEditor(typeof(RedDotView))]
public class RedDotViewEditor : Editor
{
    private List<string> nodePathList;
    private RedDotView cmp = null;
    private SerializedProperty red;
    private SerializedProperty redWithCount;
    private SerializedProperty redCount;
    private SerializedProperty news;

    void OnEnable()
    {
        cmp = (RedDotView)target;

        red = serializedObject.FindProperty("red");
        redWithCount = serializedObject.FindProperty("redWithCount");
        redCount = serializedObject.FindProperty("redCount");
        news = serializedObject.FindProperty("news");

        nodePathList = RedDotEditorUtil.GetNodeTreeList();
    }

    public override void OnInspectorGUI()
    {
        EditorGUILayout.PropertyField(red);
        EditorGUILayout.PropertyField(redWithCount);
        EditorGUILayout.PropertyField(redCount);
        EditorGUILayout.PropertyField(news);

        if (serializedObject.hasModifiedProperties)
        {
            serializedObject.ApplyModifiedProperties();
        }

        EditorGUILayout.Space(10);

        bool dirty = false;
        var count = EditorGUILayout.Toggle("显示红点数量", cmp.showCount);
        if (count != cmp.showCount)
        {
            cmp.showCount = count;
            dirty = true;
        }

        var idx = nodePathList.IndexOf(cmp.treePath);
        var idxNew = EditorGUILayout.Popup("监听路径", idx, nodePathList.ToArray());

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("重置路径");
        if (GUILayout.Button("重置"))
        {
            idxNew = 0;
        }
        EditorGUILayout.EndHorizontal();

        if (idxNew >= 0 && nodePathList.Count > idxNew && idxNew != idx)
        {
            cmp.treePath = nodePathList[idxNew];
            dirty = true;
        }

        if (dirty)
        {
            EditorUtility.SetDirty(target);
        }
    }
}
#endif